package com.netposa.datawarehouse.statistics.controller;

import com.alibaba.fastjson.JSONObject;
import com.netposa.appwebres.WebResCallback;
import com.netposa.appwebres.common.WebResCriteria;
import com.netposa.appwebres.common.WebResInfo;
import com.netposa.datawarehouse.aggregator.web.model.FtrCondition;
import com.netposa.datawarehouse.statistics.service.StructureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/structure_count"})
public class StructureCountController {
   @Autowired
   StructureService structureService;

   @GetMapping({"/typecount"})
   public WebResInfo typeCount(final String types) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(StructureCountController.this.structureService.typeCount(types));
         }
      }).sendRequest(new Object[0]);
   }

   @GetMapping({"/timelinecount"})
   public WebResInfo timelineCount(final String types) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(StructureCountController.this.structureService.timelineCount(types));
         }
      }).sendRequest(new Object[0]);
   }

   @GetMapping({"/time_axis"})
   public WebResInfo timelineCountByDay(final String types, final int day) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... objects) {
            criteria.addSingleResult(StructureCountController.this.structureService.timelineCountByDays(types, day));
         }
      }).sendRequest(new Object[0]);
   }

   @GetMapping({"/taskcount"})
   public WebResInfo taskCount() {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(StructureCountController.this.structureService.taskCount());
         }
      }).sendRequest(new Object[0]);
   }

   @PostMapping({"/cameracount"})
   public WebResInfo cameracount(@RequestBody final String regionName) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(StructureCountController.this.structureService.cameracount(JSONObject.parseObject(regionName).getString("name")));
         }
      }).sendRequest(new Object[0]);
   }

   @PostMapping({"/regioncount"})
   public WebResInfo regioncount(@RequestBody final String regionName) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(StructureCountController.this.structureService.regioncount(JSONObject.parseObject(regionName).getString("name")));
         }
      }).sendRequest(new Object[0]);
   }

   @GetMapping({"/camera_structure/{cameraId}"})
   public WebResInfo cameraStructure(@PathVariable final String cameraId) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            criteria.addSingleResult(StructureCountController.this.structureService.cameraStructure(cameraId));
         }
      }).sendRequest(new Object[0]);
   }

   @PostMapping({"/count_structure_number"})
   public WebResInfo getStructureNumber(@RequestBody final FtrCondition condition) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... objects) {
            criteria.addSingleResult(StructureCountController.this.structureService.statisticStructureNumber(condition));
         }
      }).sendRequest(new Object[0]);
   }

   @RequestMapping({"/ty_vender_info"})
   public WebResInfo venderInfo(@RequestParam("startTime") final Long startTime, @RequestParam("endTime") final Long endTime, @RequestParam("type") final String type) {
      return (new WebResCallback() {
         public void execute(WebResCriteria webResCriteria, Object... objects) {
            webResCriteria.addSingleResult(StructureCountController.this.structureService.venderInfo(startTime, endTime, type));
         }
      }).sendRequest(new Object[0]);
   }
}
